package greed;
// 53. 最大子数组和
public class LeetCode53 {
    public int maxSubArray(int[] nums) {
        if (nums.length == 1){
            return nums[0];
        }
        int result = Integer.MIN_VALUE;
        int count = 0;
        for (int i = 0; i < nums.length; i++) {
            count += nums[i];
            if (count > result){
                result = count;
            }
            if (count < 0){
                count = 0;
            }
        }
        return result;
    }
}
